package org.ala.tiktools.rpc.tcp.client_server;

import org.ala.tiktools.rpc.client_server.service.impls.AbstractRpcServiceReceiver;
import org.ala.tiktools.rpc.netty.handler.RpcChannelInitializer;
import org.ala.tiktools.rpc.tcp.config.RpcTcpConfigInfo;
import org.springframework.context.ApplicationContext;

import io.netty.channel.Channel;


/**
 * netty服务端
 *
 * @author ala
 * @date 2025-04-09 12:55
 */
public class TcpReceiver extends AbstractRpcServiceReceiver {


    @Override
    public Channel init(ApplicationContext applicationContext) {
        //  启动netty服务端
        int bossCount = RpcTcpConfigInfo.INSTANCE.getServerBossCount(), workerCount = RpcTcpConfigInfo.INSTANCE.getServerWorkerCount();
        int port = RpcTcpConfigInfo.INSTANCE.getPort();
        return TcpNettyTools.bind(bossCount, workerCount, port, new RpcChannelInitializer(getExecutor(), false, true, this::channelRegistered, this::channelUnRegistered));
    }
}
